package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;

/**UserAccount userAccount1=new UserAccount("001-0001","sample_pass1","Shaunak","shaunak.s09@gmail.com","8884055989");
 //    UserAccount userAccount2=new UserAccount("002-0002","sample_pass2","Sinha","shaunaks@thoughtworks.com","9739591769");
 //    ArrayList<UserAccount> userAccountList=new ArrayList<UserAccount>();

 * Created by shaunaks on 25/02/14.
 */
public class Register {

    private ArrayList<Book> bookList=new ArrayList<Book>();
    private ArrayList<Movie> movieList=new ArrayList<Movie>();

    private ArrayList<Book> borrowedBookList =new ArrayList<Book>();
    private ArrayList<Movie> borrowedMovieList=new ArrayList<Movie>();

//

    public ArrayList getListOfAvailableBooks()
    {
        return bookList;
    }
    public ArrayList getListOfBorrowedBooks(){ return borrowedBookList; }
    public ArrayList<Movie> getListOfAvailableMovies() {return movieList;}
    public ArrayList<Movie> getListOfBorrowedMovies() {return borrowedMovieList;}


    public boolean addBookToRegister(String bookAttributes)
    {
        String[] separatedBookAttributes=bookAttributes.split(":");
        Book book=new Book(separatedBookAttributes[0],separatedBookAttributes[1],separatedBookAttributes[2]);
        bookList.add(book);
        return true;
    }



    public boolean returnBookToRegister(String bookIsbn)
    {
        for(Book book: borrowedBookList)
        {
            if(bookIsbn.equals(book.getIsbn()))
            {
                borrowedBookList.remove(book);
                bookList.add(book);
                return true;
           }
        }
        return false;
    }




    public Book checkOutBookFromRegister(String bookIsbn)
    {
        for(Book book : bookList)
        {
            if(bookIsbn.equals(book.getIsbn()))
            {
                bookList.remove(book);
                borrowedBookList.add(book);

                return book;
            }
        }
        return null;
    }


    public boolean addMovieToRegister(String movieAttributes)
    {
        String[] separatedMovieAttributes=movieAttributes.split(":");
        Movie movie=new Movie(separatedMovieAttributes[0],separatedMovieAttributes[1],separatedMovieAttributes[2],separatedMovieAttributes[3]);
        movieList.add(movie);
        return true;
    }


    public Movie checkOutMovieFromRegister(String movieName)
    {
        for(Movie movie : movieList)
        {
            if(movieName.equals(movie.getName()))
            {
                movieList.remove(movie);
                borrowedMovieList.add(movie);
                return movie;
            }
        }
        return null;

    }

    public boolean returnMovieToRegister(String movieName)
    {
        for(Movie movie: borrowedMovieList)
        {
            if(movieName.equals(movie.getName()))
            {
                borrowedMovieList.remove(movie);
                movieList.add(movie);
                return true;
            }
        }
        return false;
    }
}
